package com.tjakus.properties;

import com.tjakus.hibernate.HibernateUtil;

/**
 * This is a static class which represents all settings/properties which will be
 * used.
 * 
 * @author tjakus
 * 
 */

public class Property {

	public static String IS_PROXY_ENABLED;
	public static String PROXY_HOST;
	public static int PROXY_PORT;
	public static String CRON_GET_PAGE_JOB;
	public static String CRON_JOB_SEND_MAIL;
	public static String CRON_JOB_DB_CLEANUP;
	public static String EMAIL_USERNAME;
	public static String EMAIL_PASSWORD;
	public static long CLEANUP_PERIOD_IN_SEC;
	public static String CRON_JOB_UPDATE_STATISTICS;
	public static String CRON_JOB_READ_PROPERTY;

	/**
	 * This method retrieves all settings/properties from database and initializes
	 * them. It returns true or false.
	 * 
	 */
	public static boolean initializeProperties() {
		String temporarilySetting;
		IS_PROXY_ENABLED = HibernateUtil.getSettingsValueByName("IS_PROXY_ENABLED");
		if (IS_PROXY_ENABLED == null)
			return false;
		PROXY_HOST = HibernateUtil.getSettingsValueByName("PROXY_HOST");
		if (PROXY_HOST == null)
			return false;
		temporarilySetting = HibernateUtil.getSettingsValueByName("PROXY_PORT");
		if (temporarilySetting == null)
			return false;
		PROXY_PORT = Integer.parseInt(temporarilySetting);
		CRON_GET_PAGE_JOB = HibernateUtil
				.getSettingsValueByName("CRON_GET_PAGE_JOB");
		if (CRON_GET_PAGE_JOB == null)
			return false;
		CRON_JOB_SEND_MAIL = HibernateUtil
				.getSettingsValueByName("CRON_JOB_SEND_MAIL");
		if (CRON_JOB_SEND_MAIL == null)
			return false;
		CRON_JOB_DB_CLEANUP = HibernateUtil
				.getSettingsValueByName("CRON_JOB_DB_CLEANUP");
		if (CRON_JOB_DB_CLEANUP == null)
			return false;
		EMAIL_USERNAME = HibernateUtil.getSettingsValueByName("EMAIL_USERNAME");
		if (EMAIL_USERNAME == null)
			return false;
		EMAIL_PASSWORD = HibernateUtil.getSettingsValueByName("EMAIL_PASSWORD");
		if (EMAIL_PASSWORD == null)
			return false;
		temporarilySetting = HibernateUtil
				.getSettingsValueByName("CLEANUP_PERIOD_IN_SEC");
		if (IS_PROXY_ENABLED == null)
			return false;
		CLEANUP_PERIOD_IN_SEC = Long.parseLong(temporarilySetting);
		CRON_JOB_UPDATE_STATISTICS = HibernateUtil.getSettingsValueByName("CRON_JOB_UPDATE_STATISTICS");
		if (CRON_JOB_UPDATE_STATISTICS == null)
			return false;
		CRON_JOB_READ_PROPERTY = HibernateUtil.getSettingsValueByName("CRON_JOB_READ_PROPERTY");
		if (CRON_JOB_READ_PROPERTY == null)
			return false;
		
		return true;
	}

}
